use utils::curd::model::*;

#[endpoint_derive_for(usage = "query")]
pub struct GetRoleListReq {
    pub page: Option<i32>,
    pub page_size: Option<i32>,
    pub name: Option<String>,
    pub code: Option<String>,
    pub status: Option<i32>,
}

#[endpoint_derive_for(usage = "response")]
pub struct GetRoleListRes {
    pub total: i32,
    pub roles: Vec<RoleInfo>,
    pub message: String,
    pub code: i32,
}

#[endpoint_derive_for(usage = "response")]
pub struct RoleInfo {
    pub id: i64,
    pub name: String,
    pub code: String,
    pub description: String,
    pub parent_id: i64,
    pub sort: i32,
    pub status: i32,
    pub remark: String,
    pub created_at: String,
    pub updated_at: String,
    pub children: Vec<RoleInfo>,
    pub menus: Vec<MenuInfo>,
}

#[endpoint_derive_for(usage = "response")]
pub struct MenuInfo {
    pub id: i64,
    pub name: String,
    pub path: String,
    pub perm_code: String,
}

#[derive(Debug, Deserialize, ToParameters)]
pub struct GetRoleInfoReq {
    pub role_id: i64,
}

#[endpoint_derive_for(usage = "response")]
pub struct GetRoleInfoRes {
    pub role: Option<RoleInfo>,
    pub message: String,
    pub code: i32,
}

#[endpoint_derive_for(usage = "body")]
pub struct CreateRoleReq {
    #[validate(length(min = 1, message = "角色名称不得为空"))]
    pub name: String,
    #[validate(length(min = 1, message = "角色代码不得为空"))]
    pub code: String,
    pub sort: i32,
    pub status: i32,
    pub remark: String,
    pub parent_id: i64,
}

#[endpoint_derive_for(usage = "response")]
pub struct CreateRoleRes {
    pub role_id: i64,
    pub message: String,
    pub code: i32,
}

#[endpoint_derive_for(usage = "body")]
pub struct UpdateRoleReq {
    #[serde(skip)]
    pub role_id: i64,
    #[validate(length(min = 1, message = "角色名称不得为空"))]
    pub name: String,
    #[validate(length(min = 1, message = "角色代码不得为空"))]
    pub code: String,
    pub sort: i32,
    pub status: i32,
    pub remark: String,
    pub parent_id: i64,
}

#[endpoint_derive_for(usage = "response")]
pub struct UpdateRoleRes {
    pub message: String,
    pub code: i32,
}

#[endpoint_derive_for(usage = "body")]
pub struct DeleteRoleReq {
    #[validate(length(min = 1, message = "角色ID不得为空"))]
    pub role_ids: Vec<i64>,
}

#[endpoint_derive_for(usage = "response")]
pub struct DeleteRoleRes {
    pub message: String,
    pub code: i32,
}

#[endpoint_derive_for(usage = "body")]
pub struct BindRolesByUserIdReq {
    pub user_id: i64,
    pub role_ids: Vec<i64>,
}

#[endpoint_derive_for(usage = "response")]
pub struct BindRolesByUserIdRes {
    pub message: String,
    pub code: i32,
}

#[endpoint_derive_for(usage = "response")]
pub struct GetRoleTreeRes {
    pub roles: Vec<RoleInfo>,
    pub message: String,
    pub code: i32,
}
